import requests

from geektime_0.service.litemall.config.base_data import url


class Session:
    _access_token = None

    def __init__(self, username, password):
        self._access_token = self.refresh_token(username, password)
        Session._access_token = self._access_token

    # 从登录接口获取token
    def refresh_token(self, username, password):
        r = requests.post(
            f'{url}/wx/auth/login',
            json = {'username': username, 'password': password}
        )
        return r.json()['data']['token']

    def get_token(self):
        return self._access_token
